var isIE = (navigator.appName == 'Microsoft Internet Explorer');
var isGecko = (navigator.userAgent.indexOf('Gecko') != -1);
var isOpera = (window.opera);

function _posX(o) {
	var l = o.offsetLeft;
	var p = o.offsetParent;

	while(p) {

		/* IE relative hack */
		if (p.style.position.toLowerCase() == 'relative' && isIE) {
			p = p.offsetParent;
			continue;
		}

		l += p.offsetLeft;
		p = p.offsetParent;
	}
	return l;
}
function _posY(o) {
	var t = o.offsetTop;
	var p = o.offsetParent;

	while(p){
		t += p.offsetTop;
		p = p.offsetParent;
	}
	return t;
}
function setcookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function _addevent(o, e, f) {
	if (o.addEventListener) {
		o.addEventListener(e, f, false);
	}
	else if (o.attachEvent) {
		o.attachEvent('on' + e, f);
	}
}
function _removeevent(o, e, f) {
	if (o.removeEventListener) {
		o.removeEventListener(e, f, false);
	}
	else if (o.detachEvent) {
		o.detachEvent('on' + e, f);
	}
}
function _cleannode(o) {
	var c = o.firstChild;
	while (c) {
		o.removeChild(c);
		c = o.firstChild;
	}
}
function _clearselect(o) {
	if (!o.options) {
		return;
	}
	var n = (arguments.length > 1) ? 1 : 0;
	var l = o.options.length;
	while (l > n) {
		o.options[l - 1] = null;
		l = o.options.length;
	}
}
function _setselect(sel, val) {
	for (var i = 0; i < sel.options.length; i++) {
		if (sel.options[i].value == val) {
			//sel.selectedIndex = i;
			sel.options[i].selected = true;
			return;
		}
	}
	sel.selectedIndex = 0;
}
function _copyselect(from, to) {

	_clearselect(to);

	var n = from.options.length;
	for (var i = 0; i < n; i++) {
		to.options[i] = new Option(from.options[i].text, from.options[i].value);
		if (from.options[i].className) {
			to.options[i].className = from.options[i].className;
		}
	}
}
function disableform(f, b) {
	if (f.tagName.toLowerCase() != 'form') {
		return false;
	}

	for (var i = 0; i < f.elements.length; i++) {
		f.elements[i].disabled = b;
		f.elements[i].tagName;
	}
}
var _obj = function (s) {
	return document.getElementById(s);
}
function isemail(str){
	var re = /[^\s@]+@[^\s@]+\.[a-zA-Z]{2,4}/;
	return re.test(str);
}

function ipinfo(ip) {
	var u = 'http://whois.domaintools.com/' + ip;
	openwin(u, window.screen.availWidth - 20, window.screen.availHeight - 20, 1, 1);
}

function trim(str) {
	str = str.replace(/^\s+/, '');
	return str.replace(/\s+$/, '');
}
function ltrim(str) {
	return str.replace(/^\s+/, '');
}
function ent(str) {
	str = str.replace(/&/g, '&amp;');
	str = str.replace(/</g, '&lt;');
	return str.replace(/>/g, '&gt;');
}

function _go(s) {
	window.location.href = s;
}
function node_text(o) {
	var _t = (o.childNodes.length > 1) ? o.childNodes[1] : o.firstChild;
	return (_t) ? _t.nodeValue : '';
}
function firstTag(o) {
	var n = o.childNodes.length;
	for (var i = 0; i < n; i++) {
		if (o.childNodes[i].nodeType == 1) { // NODE_ELEMENT
			return o.childNodes[i];
		}
	}

	return null;
}
function nextTag(o) {
	var n = o.nextSibling;
	while (n) {
		if (n.nodeType == 1) { // NODE_ELEMENT
			return n;
		}
		n = n.nextSibling;
	}

	return null;
}
function _innerText(o) {
	var res = new Array();

	var n = o.childNodes.length;
	for (var i = 0; i < n; i++) {
		if (o.childNodes[i].nodeType == 3) { // NODE_TEXT
			res[res.length] = o.childNodes[i].nodeValue;
		}
	}
	return res.join(' ');
}
function iText(o) {
	return (typeof(o.innerText) != 'undefined') ? o.innerText : o.textContent;
}
function sText(o, s) {
	if (typeof(o.innerText) != 'undefined') {
		o.innerText = s;
	}
	else {
		o.textContent = s;
	}
}
function in_array(e, a) {
	for (var i = 0; i < a.length; i++) {
		if (a[i] == e) {
			return true;
		}
	}
	return false;
}

function gethttp(u, f) {
	var x = _xmlhttp();
	if (x) {
		x.open("GET", u, true);
		x.onreadystatechange = _bind(x, f);
		x.send(null);
	}
}
function posthttp(u, f, d) {
	var x = _xmlhttp();
	if (x) {
		x.open("POST", u, true);
		x.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		x.onreadystatechange = _bind(x, f);
		x.send(d);
	}
}
function _xmlhttp() {
	var o = null;
	try { o = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) { try { o = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { } }
	if(!o) { try { o = new XMLHttpRequest(); } catch(e) { } }
	return o;
}
function _bind(o, f) {
	var t = o;
	return function(){
		f(t);
	}
}
function openwin(url, winX, winY, scroll, resize) {
	var px = (window.screen.availWidth - winX) / 2;
	var py = (window.screen.availHeight - winY) / 2;
	window.open(url, "", "menubar=0, toolbar=0, location=0, status=0, scrollbars=" + scroll + ", width=" + winX + ", height=" + winY + ", resizable=" + resize + ", left=" + px + ", top=" + py);
}
